import request from "@/utils/request";
import {
  AddTaskDataRequest,
  CourseExperimentPageVO,
  CourseExperimentQuery,
  DetailTaskDataRequest,
  viewTaskDataRequest,
} from "./types";
import { AxiosPromise } from "axios";

/**
 * 课程分页列表
 *
 * @param queryParams
 */
export function getExperimentPage(
  queryParams: CourseExperimentQuery,
  courseId: number
): AxiosPromise<PageResult<CourseExperimentPageVO[]>> {
  return request({
    url: "/api/v1/system/course/experiment/page/" + courseId,
    method: "get",
    params: queryParams,
  });
}

/**
 * 添加任务
 *
 * @param queryParams
 */
export function addExperimentTask(
  queryParams: AddTaskDataRequest,
  courseId: number
): AxiosPromise<string> {
  return request({
    url: "/api/v1/course/experiment/add",
    method: "post",
    params: {
      courseId,
    },
    data: queryParams,
  });
}

/**
 * 删除任务
 *
 * @param experimentId
 */
export function deleteTask(experimentId: number): AxiosPromise<string> {
  return request({
    url: "/api/v1/course/experiment/delete/" + experimentId,
    method: "delete",
  });
}

/**
 * 查看任务详情
 *
 * @param experimentId
 */
export function viewTask(
  experimentId: number
): AxiosPromise<viewTaskDataRequest> {
  return request({
    url: "/api/v1/course/experiment/view",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 点击查看任务详情
 *
 * @param experimentId
 */
export function getSubmitExperiment(
  experimentId: number
): AxiosPromise<DetailTaskDataRequest> {
  return request({
    url: "/api/v1/course/experiment/submitDetail",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 点击查看任务详情
 *
 * @param experimentId
 */
export function detailTask(
  experimentId: number
): AxiosPromise<DetailTaskDataRequest> {
  return request({
    url: "/api/v1/course/experiment/detail",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 点击查看任务详情
 *
 * @param experimentId
 */
export function detailSubmitTask(
  experimentId: number
): AxiosPromise<DetailTaskDataRequest> {
  return request({
    url: "/api/v1/course/experiment/submitDetail",
    method: "get",
    params: {
      experimentId,
    },
  });
}

/**
 * 修改任务
 *
 * @param queryParams
 */
export function editTask(
  queryParams: viewTaskDataRequest,
  courseId: number
): AxiosPromise<string> {
  return request({
    url: "/api/v1/course/experiment/update",
    method: "post",
    params: {
      courseId,
    },
    data: queryParams,
  });
}

/**
 * 检验此任务是否合法
 *
 * @param queryParams
 */
export function verifyExpSubmit(experimentId: number, courseId: number) {
  return request({
    url: "/api/v1/course/experiment/verifyExpSubmit",
    method: "get",
    params: {
      experimentId,
      courseId,
    },
  });
}
